/*****************************************************************************

File:   otkCreateIntfData.java

Date          Build     Author        Version    Comments
27-Dec-12    P-20-20    dshah          $$1        Created
20-mar-15 P-30-05 gshmelev $$2  called GetCurrentSession

****************************************************************************/


package com.ptc.otkjavaexamples;

import com.ptc.cipjava.*;
import com.ptc.pfc.pfcSession.*;
import com.ptc.pfc.pfcCommand.*;
import com.ptc.pfc.pfcGlobal.*;
import com.ptc.pfc.pfcModel.*;
import com.ptc.pfc.pfcModelItem.*;
import com.ptc.pfc.pfcFeature.*;
import com.ptc.pfc.pfcSolid.*;
import javax.swing.JOptionPane;
import java.io.*;

import com.ptc.cipjava.*;
import com.ptc.pfc.pfcFamily.*;
import com.ptc.pfc.pfcServer.*;
import com.ptc.pfc.pfcWindow.*;
import com.ptc.wfc.wfcSolid.*;
import com.ptc.wfc.wfcCombState.*;
import com.ptc.pfc.pfcBase.*; 
import com.ptc.pfc.pfcGeometry.*;
import com.ptc.wfc.wfcGeometry.*;
import com.ptc.wfc.wfcModel.*;
import com.ptc.wfc.wfcPart.*;
import com.ptc.wfc.wfcSession.*;

/**********************************************************************
In this Example :The code gets the interfaceData handle using otk method.  
		With this handle it creates and dump the interface data information 
		in following files
		InterfaceData<modelName>.cxx
		EdgeDescs<modelName>.cxx
		QuiltDatas<modelName>.cxx
		SurfaceDescs<modelName>.cxx

		After building above files, when we run the application 
		it will create the new part with the imported feature.

**********************************************************************/


class otkCreateIntfData extends DefaultUICommandActionListener
{
    
    
    
    public otkCreateIntfData()
    {
    }
    
    
    
    
    public void OnCommand()
    {
	addCreateIntfData();
    }
    
    
    public int addCreateIntfData ()
    {
	try
	    {	

		Session		session = pfcSession.GetCurrentSession ();		
		Models		Models = session.ListModels ();
	
		Model		Model = Models.get (0);
		String ModelName = Model.GetInstanceName();	
		
		/*Here underscore "_" is removed from the model name*/
		
		String Lname = ModelName.toLowerCase();
		String name[] = Lname.split("_");
		String name1 = "";
		for(int i=0; i<name.length; i++)
		{
			char[] stringArray = name[i].toCharArray();
			stringArray[0] = Character.toUpperCase(stringArray[0]);
			name[i] = new String(stringArray);
			name1 += name[i];
		}
		

	    /* Saving the java file in the form: <moduleName>modelName.java*/
		String buffer = "InterfaceData" + name1;
		String buffer1 = buffer + ".java";
		
		FileWriter file = new FileWriter(buffer1);
		BufferedWriter f_out = new BufferedWriter (file);
		
		BaseSession bSession = (BaseSession)(session);
		WSession wSession = (WSession)(session);	
		IntfDataSourceType SrcType = wSession.GetDataSourceType(IntfType.INTF_NEUTRAL_FILE);

		Solid pSolid = (Solid)(Model);
		WSolid wSolid = (WSolid)(pSolid);
		WPart wPart = (WPart)(wSolid);
		
		EdgeRepresentation wEdgeRep = wfcPart.EdgeRepresentation_Create(1,1,1);				
		ConversionOptions wConverOption = wfcPart.ConversionOptions_Create(wEdgeRep, CurveConversionOption.PART_CURVES_AS_DEFAULT, SurfaceConversionOption.PART_SURFACES_AS_DEFAULT);		
		InterfaceData wIntfData = wPart.GetInterfaceData(wConverOption);				
		otkCreateIntfDataUtils.CreateIntfDataFile (wIntfData, name1, buffer, f_out);

		f_out.close();	

		return 0;
		
	    }
	catch (Exception e)
	    {
		System.out.println("1: " + e);
	    }
	return (0);
    }
    
};






